<?php

namespace App\Http\Resources;

use App\Models\Topic;

class TopicResource
{

    /**
     * 格式化评论列表
     * @param $topicId
     * @param int $page
     * @param int $perPage
     * @return array
     */
    public function format($topicId)
    {

        $row = (new Topic)->getRow($topicId, ['user']);

        return [
            'id' => $row['id'],
            'category_id' => $row['category_id'],
            'title' => $row['title'],
            'body' => $row['body'],
            'user_id' => $row['user_id'],
            'reply_count' => $row['reply_count'],
            'view_count' => $row['view_count'],
            'created_at' => $row['created_at'],
            'user_name' => $row['user']['name'] ?? '',
            'user_head_img' => $row['user']['http_head_img'] ?? '',
            'user_email' => $row['user']['email'] ?? ''

        ];
    }
}
